package com.cxyzy.demo.widget

import android.content.Context
import android.util.AttributeSet
import android.view.animation.Animation
import android.view.animation.LinearInterpolator
import android.view.animation.RotateAnimation
import android.widget.ImageView
import androidx.appcompat.widget.AppCompatImageView

/**
 * 自旋转imageView
 */
class RotateImageView(context: Context, attrs: AttributeSet?) : AppCompatImageView(context, attrs) {
    lateinit var animation: RotateAnimation
    init {
        startRotate()
    }

    fun startRotate() {
        val animateTime = 2000L
        animation = RotateAnimation(0.0f, 360.0f, 1, 0.5f, 1, 0.5f)
        animation.fillAfter = true
        animation.repeatCount = Animation.INFINITE
        animation.duration = animateTime
        animation.interpolator = LinearInterpolator()
        startAnimation(animation)
    }

    fun stopRotate() {
        clearAnimation()
    }

}